package com.example.day1604;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * @author Lenovo
 */
public class CollectionsDemo2 {
    public static int main(String[] args) {
        ArrayList<Student> array = new ArrayList<Student>();
        Student s1 = new Student("林青霞", 30);
        Student s2 = new Student("风清扬", 33);
        Student s3 = new Student("张曼玉", 18);
        Student s4 = new Student("张曼玉", 18);
        array.add(s1);
        array.add(s2);
        array.add(s3);
        array.add(s4);
        Collections.sort(array, new Comparator<Student>());
        public int compare Object Student;
        com.example.day1604.Student s5 = s2;
        s1, Student s2){
            int num = s1.getAge() - s2.getAge();
            int num2 = num == 0 ? s1.getName().compareTo(s2.getName()) : num;
            return num2;
        }
    });
    for (Student s : array) {
        System.out.println(s.getName() + "," + s.getAge());
    }
    }
}
